<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>分配权限</title>
<%@ include file="/common/jsp/taglibs.jsp" %>
<%@ include file="/common/jsp/headerScriptCss.jsp" %>
<link type="text/css"  rel="stylesheet"  href="${ctx}/common/css/zTreeStyle/zTreeStyle.css"/>
<script type="text/javascript" src="${ctx}/common/jquery/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript">
<!--
var setting = {
    check: {
        enable: true
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    check: {
        enable: true
    }
};

var zNodes =${purviewsList};

$(document).ready(function(){
    $.fn.zTree.init($("#treeDemo"), setting, zNodes);
    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    treeObj.expandAll(true);
});

function getPurviewIds(){
	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
	var nodes = treeObj.getCheckedNodes(true);
	var purviewIds="";
	$.each(nodes, function(i, n){
		purviewIds+=n.id+",";
		});
	if(purviewIds.length>0){
		purviewIds = purviewIds.substring(0,purviewIds.length-1);
    }else{
    	$.dialog.alert("请选择权限");
    }
	return purviewIds;
}

function toSubmit(){
	var purviewIds = getPurviewIds();
	$(":input[name='purviewIds']").val(purviewIds);
    $("#addForm").ajaxSubmit({
        url:'${ctx }/rolePurview/add',
        type:"POST",
        dataType:'json',
        success:function(data){
        	if(data.status=='success'){
                setTimeout(function(){
                    $.dialog.close();
                },600);
                showSuccess($("#main",window.parent.document));
            }else{
                setTimeout(function(){
                    $.dialog.close();
                },600);
                showError($("#main",window.parent.document));
            }
        }           
    }); 
}
//-->
</script>
</head>
<body class="dialogBody">
        <div style="padding:0px 0px 20px 0px;">
           <ul id="treeDemo" class="ztree"></ul>
        </div>
        <form id="addForm">
            <input name="roleId"  type="hidden" value="${roleId }"/>
            <input name="purviewIds" type="hidden"/>
            <p style="text-align:center;">
               <input  type="button"  class="button"  value="确定"  onclick="toSubmit();"/>
            </p>
        </form>
</body>

</html>